# share_page.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class SharePage:
    def __init__(self, driver):
        self.driver = driver
        self.url = 'http://example.com/share'
        self.share_button_locator = (By.ID, 'share-button')  # 分享按钮定位器
        self.facebook_share_locator = (By.ID, 'facebook-share')  # Facebook分享链接定位器
        self.twitter_share_locator = (By.ID, 'twitter-share')  # Twitter分享链接定位器
        self.email_share_locator = (By.ID, 'email-share')  # 电子邮件分享链接定位器
        self.copy_link_button_locator = (By.ID, 'copy-link-button')  # 复制链接按钮定位器
        self.popup_window_locator = (By.ID, 'popup-window')  # 弹窗定位器
        self.close_popup_button_locator = (By.ID, 'close-popup-button')  # 关闭弹窗按钮定位器

    # 导航到分享页面
    def navigate(self):
        self.driver.get(self.url)

    # 点击分享按钮
    def click_share_button(self):
        self.driver.find_element(*self.share_button_locator).click()

    # 获取Facebook分享链接
    def get_facebook_share_link(self):
        return self.driver.find_element(*self.facebook_share_locator).get_attribute('href')

    # 获取Twitter分享链接
    def get_twitter_share_link(self):
        return self.driver.find_element(*self.twitter_share_locator).get_attribute('href')

    # 获取电子邮件分享链接
    def get_email_share_link(self):
        return self.driver.find_element(*self.email_share_locator).get_attribute('href')

    # 点击复制链接按钮
    def click_copy_link_button(self):
        self.driver.find_element(*self.copy_link_button_locator).click()

    # 获取弹窗文本
    def get_popup_text(self):
        return self.driver.find_element(*self.popup_window_locator).text

    # 关闭弹窗
    def close_popup(self):
        self.driver.find_element(*self.close_popup_button_locator).click()